<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>hiphp</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        .layuimini-container-save {padding: 15px 35px 0 0;}
    </style>
</head>
<body>
<div class="layuimini-container layuimini-container-save">
    <form class="layui-form" action="" lay-filter="formTest">
        <input type="hidden" name="id" value="">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">管理账号</label>
            <div class="layui-input-block">
                <input type="text" name="account" placeholder="管理账号" class="layui-input" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">管理名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="管理名称" class="layui-input" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">权限组</label>
            <div class="layui-input-block">
                <select name="group_id" id="group_id" lay-filter="group_id" lay-verify="required">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">管理状态</label>
            <div class="layui-input-block">
              <input type="checkbox" name="status" lay-skin="switch" value="1" lay-text="启用|停用" lay-verify="required" checked>
            </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">确定</button>
            <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
          </div>
        </div>
      </form>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script type="module">
    import * as hi from '../../js/common/main.js'

    hi.page(() => {
        hi.getData({
            url: hi.ADMIN_GET,
            success: (json) => {
                if (json.code == 200) {
                    hi.loadSelect(json.data.groups, '#group_id')

                    hi.form.val("formTest", json.data.one);
                }
            }
        })

        hi.saveOne({
            url: hi.ADMIN_SAVE,
            before: (data) => {
                if ( ! data.status) {
                    data.status = '0'
                }

                return data
            }
        })
    })
</script>

</body>
</html>